<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        //   输入: [
        // ​         { key: 'name', value: 'zhangsan' },
        // ​         { key: 'age', value: 18 },
        // ​         { key: 'sex', value: 'male' },
        // ​         { key: 'weight', value: 100 }
        //   ]

        //   返回: { name: 'zhangsan', age: 18, sex: 'male', weight: 100 }

        function arr2obj (arr) {
            const result = {};
            for (const item of arr) { // item: { key: 'name', value: 'zhangsan' },
                const key = item.key; // 'name'
                const value = item.value; // 'zhangsan'
                result[key] = value; // result['name'] = 'zhangsan'
            }
            return result;
        }

        console.log( arr2obj([
            { key: 'name', value: 'zhangsan' },
            { key: 'age', value: 18 },
            { key: 'sex', value: 'male' },
            { key: 'weight', value: 100 },
        ]) ); // { name: 'zhangsan', age: 18, sex: 'male', weight: 100 }

    </script>
</body>
</html>